/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package idea.countries;


import java.awt.BorderLayout;
import javax.swing.Action;
import javax.swing.JComponent;
import org.netbeans.api.settings.ConvertAsProperties;
import org.netbeans.spi.palette.PaletteActions;
import org.netbeans.spi.palette.PaletteFactory;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.Lookup;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.Lookups;


/**
 * Top component which displays something.
 */
@ConvertAsProperties(
        dtd = "-//idea.countries//Country//EN" ,
        autostore = false )
@TopComponent.Description(
        preferredID = "CountryTopComponent" ,
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS )
@TopComponent.Registration( mode = "editor" , openAtStartup = false )
@ActionID( category = "Window" , id = "idea.countries.CountryTopComponent" )
@ActionReference( path = "Menu/Window" , position = 2000 )
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_CountryAction" ,
        preferredID = "CountryTopComponent" )
@Messages(
        {
    "CTL_CountryAction=Country" ,
    "CTL_CountryTopComponent=Country Window" ,
    "HINT_CountryTopComponent=This is a Country window"
} )
public final class CountryTopComponent extends TopComponent
{

    private static CountryTopComponent instance;
    
    //private TransferHandler th = new CountryTransferHandler();
    
    
    public CountryTopComponent()
    {
        initComponents();
        setName( Bundle.CTL_CountryTopComponent() );
        setToolTipText( Bundle.HINT_CountryTopComponent() );
        
       // jTextArea1.setTransferHandler( th);

        associateLookup( Lookups.fixed( PaletteFactory.createPalette( new AbstractNode(Children.create( new CategoryChildFactory(), true)) , new PaletteActions()
        {
            @Override
            public Action[] getImportActions()
            {
                return null;
            }


            @Override
            public Action[] getCustomPaletteActions()
            {
                return null;
            }


            @Override
            public Action[] getCustomCategoryActions( Lookup lkp )
            {
                return null;
            }


            @Override
            public Action[] getCustomItemActions( Lookup lkp )
            {
                return null;
            }


            @Override
            public Action getPreferredAction( Lookup lkp )
            {
                return null;
            }

        } ) ) );
        
        GraphSceneImpl scene = new GraphSceneImpl();
        JComponent view = scene.createView();                    // view is added to scrollpane viewport view
        scenePane.setViewportView( view );
        add(scene.createSatelliteView(), BorderLayout.WEST);     // satellite view is added to Top Component
        

    }
    
//    private final class CountryTransferHandler extends TransferHandler {
//
//
//        @Override
//        public boolean importData( TransferSupport support )
//        {
//            try
//            {
//                Country country = (Country) support.getTransferable().getTransferData( Country.DATA_FLAVOR);
//                jTextArea1.setText(jTextArea1.getText() + "\n" + country.getName());
//                return true;
//            }
//            catch ( UnsupportedFlavorException ex )
//            {
//                Exceptions.printStackTrace( ex );
//            }
//            catch ( IOException ex )
//            {
//                Exceptions.printStackTrace( ex );
//            }
//            return false;
//        }
//
//
//        @Override
//        public boolean canImport( TransferSupport support )
//        {
//            return support.isDataFlavorSupported( Country.DATA_FLAVOR );
//        }
//        
//    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        btnSave = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        scenePane = new javax.swing.JScrollPane();

        setLayout(new java.awt.BorderLayout());

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        org.openide.awt.Mnemonics.setLocalizedText(btnSave, org.openide.util.NbBundle.getMessage(CountryTopComponent.class, "CountryTopComponent.btnSave.text")); // NOI18N
        btnSave.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnSaveActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(btnClear, org.openide.util.NbBundle.getMessage(CountryTopComponent.class, "CountryTopComponent.btnClear.text")); // NOI18N
        btnClear.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnClearActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(btnCancel, org.openide.util.NbBundle.getMessage(CountryTopComponent.class, "CountryTopComponent.btnCancel.text")); // NOI18N
        btnCancel.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(btnSave)
                .addGap(254, 254, 254)
                .addComponent(btnClear)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 255, Short.MAX_VALUE)
                .addComponent(btnCancel)
                .addGap(28, 28, 28))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(29, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClear)
                    .addComponent(btnSave)
                    .addComponent(btnCancel))
                .addGap(25, 25, 25))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(scenePane, javax.swing.GroupLayout.PREFERRED_SIZE, 631, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scenePane, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
                .addGap(23, 23, 23))
        );

        add(jPanel1, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents

    private void btnClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClearActionPerformed
    {//GEN-HEADEREND:event_btnClearActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnClearActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSaveActionPerformed
    {//GEN-HEADEREND:event_btnSaveActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnCancelActionPerformed
    {//GEN-HEADEREND:event_btnCancelActionPerformed
        this.close();
    }//GEN-LAST:event_btnCancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnClear;
    private javax.swing.JButton btnSave;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane scenePane;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened()
    {
        // TODO add custom code on component opening
    }


    @Override
    public void componentClosed()
    {
        // TODO add custom code on component closing
    }


    void writeProperties( java.util.Properties p )
    {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty( "version" , "1.0" );
        // TODO store your settings
    }


    void readProperties( java.util.Properties p )
    {
        String version = p.getProperty( "version" );
        // TODO read your settings according to their version
    }
    

}
